import { loginApi } from '@/api/login';
import { useStorage } from '@vueuse/core';
import { defineStore } from 'pinia';
export const userStore = defineStore('user', {
  state: () => ({
    token: <any>useStorage('token', ''),
  }),
  actions: {
    handelLogin(loginData) {
      return new Promise<void>((resolve, reject) => {
        loginApi(loginData)
          .then((response) => {
            const { tokenType, accessToken } = response.data;
            this.token = tokenType + ' ' + accessToken; // Bearer eyJhbGciOiJIUzI1NiJ9.xxx.xxx
            resolve();
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
  },
});
